#!/bin/bash

#  查看k8s可用版本（当前最新的版本为 v1.20.4 ，我们用一个早点的版本进行对比）
yum list  kubelet --showduplicates

#  卸载当前版本的k8s
yum erase -y kubelet kubectl kubeadm

#  安装指定版本的k8s，三个组件的版本要一致
yum install -y kubelet-1.19.8-0 kubectl-1.19.8-0 kubeadm-1.19.8-0

#  预先下载k8s需要的docker image。最后的版本号可以不指定，默认下载kubelet对应的版本号
kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.19.8-0

#  查看下载下来的docker image
[root@k8s-master2 ~]# docker images 
REPOSITORY                                                        TAG        IMAGE ID       CREATED         SIZE
registry.aliyuncs.com/google_containers/kube-proxy                v1.19.8    ea03182b84a2   3 weeks ago     118MB
registry.aliyuncs.com/google_containers/kube-apiserver            v1.19.8    9ba91a90b7d1   3 weeks ago     119MB
registry.aliyuncs.com/google_containers/kube-controller-manager   v1.19.8    213ae7795128   3 weeks ago     111MB
registry.aliyuncs.com/google_containers/kube-scheduler            v1.19.8    919a3f36437d   3 weeks ago     46.5MB
registry.aliyuncs.com/google_containers/etcd                      3.4.13-0   0369cf4303ff   6 months ago    253MB
registry.aliyuncs.com/google_containers/coredns                   1.7.0      bfe3a36ebd25   8 months ago    45.2MB
registry.aliyuncs.com/google_containers/pause                     3.2        80d28bedfe5d   13 months ago   683kB

#  初始化集群中第一个主节点:一般情况下不需要指定版本号，为了使用flannel网络插件，pod网络必须为 10.244.0.0/16
kubeadm init \
	--image-repository registry.aliyuncs.com/google_containers \
	--kubernetes-version v1.20.4 \
	--control-plane-endpoint k8s-master1 \
	--apiserver-advertise-address 10.12.30.101 \
	--pod-network-cidr 10.244.0.0/16 \
	--upload-certs

#  在master上配置环境变量
echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> /etc/profile.d/kube.sh && source /etc/profile

#  配置好环境变量，就可以使用kubectl命令了，因为还未安装网络插件，所以节点状态为NotReady
[root@k8s-master1 ~]# kubectl get nodes
NAME          STATUS     ROLES                  AGE     VERSION
k8s-master1   NotReady   control-plane,master   6m23s   v1.20.4

#  部署网络插件 flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

#  网络插件部署完成后，master的状态才能从 NotReady 变成 Ready
[root@k8s-master1 ~]# kubectl get nodes
NAME          STATUS   ROLES                  AGE   VERSION
k8s-master1   Ready    control-plane,master   14m   v1.20.4

#  查看k8s服务对应的pods
[root@k8s-master1 ~]# kubectl get pods -n kube-system
NAME                                  READY   STATUS    RESTARTS   AGE
coredns-7f89b7bc75-fsg97              1/1     Running   0          16m
coredns-7f89b7bc75-t5lxj              1/1     Running   0          16m
etcd-k8s-master1                      1/1     Running   0          17m
kube-apiserver-k8s-master1            1/1     Running   0          17m
kube-controller-manager-k8s-master1   1/1     Running   0          17m
kube-flannel-ds-zlnc4                 1/1     Running   0          3m51s
kube-proxy-j26hl                      1/1     Running   0          16m
kube-scheduler-k8s-master1            1/1     Running   0          17m

#  查看命名空间list
[root@k8s-master1 ~]# kubectl get ns
NAME              STATUS   AGE
default           Active   20m
kube-node-lease   Active   20m
kube-public       Active   20m
kube-system       Active   20m

#  添加主节点命令(在执行kubeadm init时添加--upload-certs的话，可以略过下面步骤1、2)
#  1、拷贝 /etc/kubernetes 到新的节点
scp -r /etc/kubernetes 10.12.30.103:/etc/
#  2、在新的节点上删除/etc/kubernetes目录中CA以外的文件
for i in `find /etc/kubernetes/ -type f | grep -v 'a\.' ` ; do rm -rf $i ; done
#  3、在新节点上行下面命令添加master节点
kubeadm join k8s-master1:6443 --token mtlhqi.nf5cwsbgzkms2ilm \
	--discovery-token-ca-cert-hash sha256:e449b2591cbb9d7d601b3714e220ab5746e1715e5572968ecd28ac93655f247d \
	--control-plane 
#  4、在新的节点上配置环境变量 和 命令补全
echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> /etc/profile.d/kube.sh && \
kubectl completion bash >> /etc/profile.d/kube.sh && \
source /etc/profile

#  5、警告信息
	[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.5. Latest validated version: 19.03

#  添加worker节点命令
kubeadm join k8s-master1:6443 --token mtlhqi.nf5cwsbgzkms2ilm \
	--discovery-token-ca-cert-hash sha256:e449b2591cbb9d7d601b3714e220ab5746e1715e5572968ecd28ac93655f247d 

#  三个master和三个node添加完成后如下：
[root@k8s-master1 ~]# kubectl get nodes -o wide
NAME          STATUS   ROLES                  AGE     VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION           CONTAINER-RUNTIME
k8s-master1   Ready    control-plane,master   40m     v1.20.4   10.12.30.101   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.5
k8s-master2   Ready    control-plane,master   24m     v1.20.4   10.12.30.102   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.5
k8s-master3   Ready    control-plane,master   7m22s   v1.20.4   10.12.30.103   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.5
k8s-node1     Ready    <none>                 34m     v1.20.4   10.12.30.104   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.5
k8s-node2     Ready    <none>                 5m54s   v1.20.4   10.12.30.105   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.5
k8s-node3     Ready    <none>                 5m38s   v1.20.4   10.12.30.106   <none>        CentOS Linux 7 (Core)   3.10.0-1062.el7.x86_64   docker://20.10.5

#  重置k8s环境，也就是删除master和worker
kubeadm reset -f
rm -rf /etc/cni/net.d
iptables -t mangle -t filter -t nat -t raw  -F ; iptables -t mangle -t filter -t nat -t raw  -X ; systemctl restart docker
ipvsadm --clear

####################################################################################################################################
k8s基础概念	http://docs.kubernetes.org.cn

Master组件
	kube-apiserver
	ETCD
	kube-controller-manager
	kube-scheduler
	Add-ons
		DNS
		用户界面
		资源监控
		日志
Worker组件
	kubelet
	kube-proxy
	docker
	RKT
	supervisord
	fluentd























####################################################################################################################################
笔记暂时实操到这里


#  部署一个app
kubectl create deployment demoapp --image=nginx 
[root@k8s-master1 ~]# kubectl get pods 
NAME                       READY   STATUS    RESTARTS   AGE
demoapp-79b7d5f68b-b8r77   1/1     Running   0          10m

#  扩容至3副本
kubectl scale  deployment  demoapp --replicas=3 
[root@k8s-master1 ~]# kubectl get pods 
NAME                       READY   STATUS    RESTARTS   AGE
demoapp-79b7d5f68b-b8r77   1/1     Running   0          10m
demoapp-79b7d5f68b-hc2gp   1/1     Running   0          18s
demoapp-79b7d5f68b-s58sk   1/1     Running   0          18s

#  查看更多的pods信息，包括所在的node节点
[root@k8s-master1 ~]# kubectl get pods -n default -o wide
NAME                       READY   STATUS    RESTARTS   AGE    IP           NODE        NOMINATED NODE   READINESS GATES
demoapp-79b7d5f68b-b8r77   1/1     Running   0          11m    10.244.1.2   k8s-node1   <none>           <none>
demoapp-79b7d5f68b-hc2gp   1/1     Running   0          105s   10.244.2.2   k8s-node2   <none>           <none>
demoapp-79b7d5f68b-s58sk   1/1     Running   0          105s   10.244.1.3   k8s-node1   <none>           <none>

#  创建服务
[root@k8s-master1 ~]# kubectl create service clusterip demoapp --tcp=80:80
service/demoapp created

#  查看服务列表
[root@k8s-master1 ~]# kubectl get services
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
demoapp      ClusterIP   10.107.184.34   <none>        80/TCP    11s
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   31m

#  下面是马哥自己制作的一个镜像，访问容器80口可以查看容器内的主机名和ip，用于验证负载效果
docker pull ikubernetes/demoapp:v1.0

####################################################################################################################################
笔记暂时整理到这里


master需要部署的k8s服务
	kube-apiserver
	kube-controller-manager
	kube-scheduler
	etcd
worker需要部署的k8s服务
	kubelet
	kube-proxy
Add-ons 
	KubeDNS:CoreDNS
	Dashboard:Web UI
	monitor:Prometheus
	Log:ELK、Loki+Grafana
	Ingress Controller：服务的出口部署方向代理

日志收集工具：
	Filebeat 节省系统资源
	Fluentd
	fluent-bit
	logstash 占用上G内存
	Loki

k8s集群使用证书加密传输过程，双向tls认证
	kubernetes-ca
	etcd-ca
	front-proxy-ca

Kubernetes集群的部署和运行模型：
	二进制程序：
	Pod：静态Pod & 常规Pod

CNI(容器网络接口)：
	叠加：overlay
	承载：underlay

	flannel	仅实现了网络，但未实现网络策略，简单易懂易用
	Calico	实现了网络和网络策略
	Canal	flannel的网络+Calico的网络策略，已停止维护

CRI(容器Runtime接口)

CSI(容器存储接口)

容器间关系，亲密的容器放到一个pod中，共存亡，共享相同的命名空间
每个pod都会配备一个pause容器，提供共享的网络和卷

pod内通信：同一个pod中的容器间使用localhost通信
pod间通信：使用网络接口cni通信，即使两个pod在一台宿主机上
pod service之间通信：iptables或者ipvs规则（kube-proxy把集群上每一个service定义转换为自己的iptables或者ipvs规则）

CoreDNS记录每个service name和IP的对应关系
pod访问service的name，而不是ip

外部访问service，通过节点网络进来，映射到对应的service上


API Server
	RESTful，资源resource
	资源类型：Pod、Deployment、Service

命令式命令
	命令，及其选项（从选项中读取配置数据）来实现
命令式配置文件
	命令，从配置文件加载配置数据
声明式配置文件
	声明式命令，从配置文件加载配置数据

资源规范，配置清单文件：json或者yaml文件格式
apiVersion	资源对象所属的API群组及版本
kind		资源类型
metadata	资源对象的原数据
spec		所需状态，或称为期望状态


apiVersion: v1
kind: Pod
metadata:
  name: mypod
  labels:
    app: mypod
    release: canary
spec:
  containers:
  - name: demoapp
    image: nginx

kubectl create -f mypod.yml
pod/mypod created
[root@k8s-master1 ~]# kubectl get pods mypod
NAME    READY   STATUS    RESTARTS   AGE
mypod   1/1     Running   0          11s
[root@k8s-master1 ~]# kubectl get pods mypod -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP             NODE        NOMINATED NODE   READINESS GATES
mypod   1/1     Running   0          28s   10.244.2.152   k8s-node2   <none>           <none>
[root@k8s-master1 ~]# kubectl get pods mypod --show-labels
NAME    READY   STATUS    RESTARTS   AGE   LABELS
mypod   1/1     Running   0          53s   app=mypod,release=canary
[root@k8s-master1 ~]# kubectl get pods mypod -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2021-03-05T10:02:39Z"
  labels:
    app: mypod
    release: canary
  managedFields:
............
pec:
  containers:
  - image: nginx
    imagePullPolicy: Always
status:
  conditions:
  - lastProbeTime: null


查看 pod 对应的API群组

[root@k8s-master1 ~]# kubectl explain pod
KIND:     Pod
VERSION:  v1


查看k8s支持的API群组名称

[root@k8s-master1 ~]# kubectl api-versions
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1
coordination.k8s.io/v1beta1
discovery.k8s.io/v1beta1
events.k8s.io/v1
events.k8s.io/v1beta1
extensions/v1beta1
flowcontrol.apiserver.k8s.io/v1beta1
networking.k8s.io/v1
networking.k8s.io/v1beta1
node.k8s.io/v1
node.k8s.io/v1beta1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

==================================================================================================================================
以上部分已经同步到印象笔记
==================================================================================================================================
用户访问pod的两种方式
	nodeIP:nodeport --> service --> pod
	ingress --> pod (但是需要service为ingress指路)

RESTful API,https
	资源类型：schema
		Pod、Deployment、Service
	对象，object
	资源规范：
		apiVersion、kind、metadata、spec(期望状态)、status(实际状态)
		控制器：负责确保将实际状态设定不断逼近或等同于期望状态
		Control Loop
			create、delete、change

工作负载型（workload），Pod
	stateful、stateless
	Deployment、DaemonSet、StatefulSet->Operator
	Job，CronJob

服务发现和负载均衡
	Service、Ingress

配置和存储
	ConfigMap、Secret
	PVC、PV
	DownwardAPI

集群级别的资源
	namespace、node、clusterrole

元数据类型
	LimitRange


获取所有资源

[root@k8s-master1 ~]# kubectl get all
NAME                           READY   STATUS    RESTARTS   AGE
pod/demoapp-5f7d8f9847-5pqdr   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-9ztq2   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-dhq2d   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-hbhgd   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-kv5jg   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-smck4   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-stj58   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-z5zmh   1/1     Running   0          3d4h
pod/demoapp-5f7d8f9847-z9j58   1/1     Running   0          3d4h
pod/mypod                      1/1     Running   0          2d21h

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/demoapp      ClusterIP   10.107.184.34   <none>        80/TCP    3d13h
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   3d13h

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/demoapp   9/9     9            9           3d5h

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/demoapp-5f7d8f9847   9         9         9       3d5h


kubectl get --raw k8s-master1:6443/api/VERSION/namespaces/NAMESPACE/pods/POD
kubectl get --raw k8s-master1:6443/api/VERSION/namespaces/NAMESPACE/deployments/DEPLOYMENT

kubectl get --raw /api/v1/namespaces/default/pods/mypod | jq
{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "mypod",
    "namespace": "default",
    "uid": "695366e4-1cff-4bda-8f78-42aa907df043",
    "resourceVersion": "90449",
    "creationTimestamp": "2021-03-05T10:02:39Z",
    "labels": {
      "app": "mypod",
      "release": "canary"
    },
    "managedFields": [
      {

[root@k8s-master1 ~]# kubectl proxy
Starting to serve on 127.0.0.1:8001

[root@k8s-master1 ~]# curl -k http://127.0.0.1:8001/api/v1/namespaces/default/pods/mypod
{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "mypod",
    "namespace": "default",
    "uid": "695366e4-1cff-4bda-8f78-42aa907df043",
    "resourceVersion": "90449",
    "creationTimestamp": "2021-03-05T10:02:39Z",
    "labels": {
      "app": "mypod",
      "release": "canary"
    },
    "managedFields": [


查看yaml文件内容
kubectl explain pod
kubectl explain pod.apiVersion
kubectl explain pod.kind
kubectl explain pod.metadata
kubectl explain pod.spec
kubectl explain pod.status

[]		列表项
required	必填项


[root@k8s-master1 ~]# kubectl explain pod
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion	<string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind	<string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata	<Object>
     Standard object‘s metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec	<Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

   status	<Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status


查看某pod信息
[root@k8s-master1 ~]# kubectl get pod mypod
NAME    READY   STATUS    RESTARTS   AGE
mypod   1/1     Running   0          2d22h

查看某pod详细信息
[root@k8s-master1 ~]# kubectl get pod mypod -o wide
NAME    READY   STATUS    RESTARTS   AGE     IP             NODE        NOMINATED NODE   READINESS GATES
mypod   1/1     Running   0          2d22h   10.244.2.152   k8s-node2   <none>           <none>

查看某pod yaml格式信息，可以做为模板创建其他pod
[root@k8s-master1 ~]# kubectl get pod mypod -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2021-03-05T10:02:39Z"
  labels:
    app: mypod
    release: canary
  managedFields:

资源引用模式
	<type>/<name>
		pod/mypod
		deployment/demoapp

删除所有pod，也可以删除指定的pod，删除后会自动重建
kubectl delete pod --all 


查看pod中的日志
kubectl logs demoapp-5f7d8f9847-bv6v4

如果pod中有多个容器，想看指定容器的日志
kubectl logs demoapp-5f7d8f9847-bv6v4 -c containerA

查看某pod的详细信息
kubectl describe pods  demoapp-5f7d8f9847-bv6v4

exec进入pod中的容器
kubectl exec demoapp-5f7d8f9847-bv6v4 -- date
kubectl exec demoapp-5f7d8f9847-bv6v4 -c containerA  -- date
kubectl exec -it  demoapp-5f7d8f9847-bv6v4 -- /bin/sh


查看namespace列表
[root@k8s-master1 ~]# kubectl get namespace
NAME              STATUS   AGE
default           Active   3d15h
kube-node-lease   Active   3d15h
kube-public       Active   3d15h
kube-system       Active   3d15h

查看某namespace
[root@k8s-master1 ~]# kubectl get namespaces/default
NAME      STATUS   AGE
default   Active   3d15h

yaml格式查看某namespace
[root@k8s-master1 ~]# kubectl get namespaces/default -o yaml
apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: "2021-03-04T17:54:13Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:phase: {}
    manager: kube-apiserver
    operation: Update
    time: "2021-03-04T17:54:13Z"
  name: default
  resourceVersion: "200"
  uid: bd8b00e4-557d-4b43-b161-3da404e425f7
spec:
  finalizers:
  - kubernetes
status:
  phase: Active

通过yml文件创建namespace
[root@k8s-master1 ~]# cat dev.yml
apiVersion: v1
kind: Namespace
metadata:
  name: dev
[root@k8s-master1 ~]# kubectl create -f dev.yml 
namespace/dev created
kubectl create namespace dev2


ot@k8s-master1 ~]# kubectl get all --namespace default
NAME                           READY   STATUS    RESTARTS   AGE
pod/demoapp-5f7d8f9847-bv6v4   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-ljgs6   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-nlz95   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-svhmh   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-tjs8q   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-vb9m9   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-w9wkt   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-wlzf7   1/1     Running   0          20m
pod/demoapp-5f7d8f9847-z9gpr   1/1     Running   0          20m

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/demoapp      ClusterIP   10.107.184.34   <none>        80/TCP    3d14h
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   3d15h

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/demoapp   9/9     9            9           3d7h

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/demoapp-5f7d8f9847   9         9         9       3d7h

删除namespace
kubectl delete namespace/dev
kubectl delete -f dev.yml

修改namespace
kubectl edit namespace dev


声明式,可以创建或者更新资源
kubectl apply -f xx.yml


查看某节点状态信息
kubectl get nodes/k8s-node1 -o yaml

k8s各节点的租约信息保存在命名空间kube-node-lease中
[root@k8s-master1 ~]# kubectl get leases -n kube-node-lease
NAME          HOLDER        AGE
k8s-master1   k8s-master1   3d20h
k8s-node1     k8s-node1     3d20h
k8s-node2     k8s-node2     3d20h
k8s-node3     k8s-node3     3d11h

[root@k8s-master1 ~]# kubectl get leases/k8s-node1 -n kube-node-lease -o yaml
apiVersion: coordination.k8s.io/v1
kind: Lease
metadata:
  creationTimestamp: "2021-03-04T18:04:01Z"
  managedFields:
  - apiVersion: coordination.k8s.io/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:ownerReferences:
          .: {}
          k:{"uid":"a7f2bf3c-91ee-41ff-a8ec-912a4fbbaa39"}:
            .: {}
            f:apiVersion: {}
            f:kind: {}
            f:name: {}
            f:uid: {}
      f:spec:
        f:holderIdentity: {}
        f:leaseDurationSeconds: {}
        f:renewTime: {}
    manager: kubelet
    operation: Update
    time: "2021-03-04T18:04:01Z"
  name: k8s-node1
  namespace: kube-node-lease
  ownerReferences:
  - apiVersion: v1
    kind: Node
    name: k8s-node1
    uid: a7f2bf3c-91ee-41ff-a8ec-912a4fbbaa39
  resourceVersion: "504107"
  uid: b411d3c2-18b9-4215-a780-66568e0a7404
spec:
  holderIdentity: k8s-node1
  leaseDurationSeconds: 40
  renewTime: "2021-03-08T14:16:50.642708Z"


使用yaml文件创建删除node
[root@k8s-master1 ~]# kubectl get nodes
NAME          STATUS   ROLES                  AGE     VERSION
k8s-master1   Ready    control-plane,master   3d20h   v1.20.4
k8s-node1     Ready    <none>                 3d20h   v1.20.4
k8s-node2     Ready    <none>                 3d20h   v1.20.4
k8s-node3     Ready    <none>                 3d11h   v1.20.4
[root@k8s-master1 ~]# cat node.yml 
apiVersion: v1
kind: Node
metadata:
  name: k8s-node11
spec:
  podCIDR: 10.244.11.0/24
  podCIDRs:
  - 10.244.11.0/24

[root@k8s-master1 ~]# kubectl apply -f node.yml 
node/k8s-node11 created
[root@k8s-master1 ~]# kubectl get nodes
NAME          STATUS    ROLES                  AGE     VERSION
k8s-master1   Ready     control-plane,master   3d20h   v1.20.4
k8s-node1     Ready     <none>                 3d20h   v1.20.4
k8s-node11    Unknown   <none>                 3s      
k8s-node2     Ready     <none>                 3d20h   v1.20.4
k8s-node3     Ready     <none>                 3d11h   v1.20.4
[root@k8s-master1 ~]# kubectl delete nodes k8s-node11
node "k8s-node11" deleted
[root@k8s-master1 ~]# kubectl get nodes
NAME          STATUS   ROLES                  AGE     VERSION
k8s-master1   Ready    control-plane,master   3d20h   v1.20.4
k8s-node1     Ready    <none>                 3d20h   v1.20.4
k8s-node2     Ready    <none>                 3d20h   v1.20.4
k8s-node3     Ready    <none>                 3d11h   v1.20.4

pod相位
	Running	运行中
	Pending	未调度成功，镜像下载中
	Succeeded 成功终止
	Failed	
	Unknown

pod中可以存在多个容器
	Sidecar		边车模式
	Adapater	适配器，让其适配到某个兼容格式
	Ambassador	大使模式

pod在启动时有2个钩子
	post start hook
	pre stop hook

pod探针
	startup probe	启动探针，给后面的存活探针加一个延迟
	liveness probe	存活探针(周期性)
	readiness probe	就绪探针(周期性)，存活未必就绪，比如tomcat启动成功了服务需要一段时间后才能接受客户端请求





	
	

